package com.neiquan.weiguan.adapter;

import android.content.Context;
import android.view.View;

import com.jcodecraeer.xrecyclerview.XRecyclerView;

import java.util.ArrayList;
import java.util.List;

/**
 * 作者 : hjb
 * 时间 : 2016/4/25.
 */
public abstract class MyBaseAdapter<T> extends XRecyclerView.Adapter {
    public Context context;
    public List<T> data = new ArrayList<T>();
    private OnRecyclerViewItemClickListener mOnItemClickListener = null;

    public MyBaseAdapter(Context context, List<T> data) {
        super();
        this.context = context;
        if (data != null) {
            this.data = data;
        }
    }

    public void clear() {
        if (data != null) {
            this.data.clear();
        }
    }

    public void append(List<T> list) {
        if (this.data != null) {
            this.data.addAll(list);
        }
        notifyDataSetChanged();
    }

    public void appendAll(List<T> list) {
        if (this.data != null) {
            this.data.clear();
            this.data.addAll(list);
        }
        notifyDataSetChanged();
    }

    //define interface
    public static interface OnRecyclerViewItemClickListener<T> {
        void onItemClick(View view, T data);
    }

    public void setOnItemClickListener(OnRecyclerViewItemClickListener listener) {
        this.mOnItemClickListener = listener;
    }
}
